<template>
	<view class="content">

		<view class="text-area">
			<text class="title"> {{ text }}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				text: '',
			}
		},
		onLoad(options) {
			console.log("options", options)
			uni.login({
				provider: 'weixin', //使用微信登录
				success: (loginRes) => {
					console.log(loginRes);
					uni.request({
						url: 'https://teamwang.zenosh.com/api/user/wxLogin', //仅为示例，并非真实接口地址。
						data: {
							code: loginRes.code
						},
						header: {
							'custom-header': 'hello' //自定义请求头信息
						},
						success: (res) => {
							
							this.saveOpenid(options.scene, res.data.openid)
						}
					});
				},
				fail: (err) => {
					console.error(err);
				},
				complete: () => {
					console.log("complete");
				},

			});
		},
		methods: {
			saveOpenid(scene, openid) {
				uni.request({
					url: 'https://teamwang.zenosh.com/api/user/saveOpenid', //仅为示例，并非真实接口地址。
					method: "POST",
					data: {
						scene: scene,
						openid: openid
					},
					success: (loginRes) => {
						this.text = "openid获取成功，后台会自动填写openid，你可以关闭此页面"
					}
				});

			},
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>